jQuery(document).ready(function() {
//    $("#scroll-bar").mCustomScrollbar({
//        scrollButtons:{
//            enable:true
//	}
//    });
//(function($){
//        $(window).load(function(){
//            $("#scroll-bar").mCustomScrollbar();
//        });
//    })(jQuery);
    
    //buy click more versions
    (function($) {
        $.fn.absoluteCenter = function() {
            this.each(function() {
                var left = -($(this).outerWidth() / 2) + 'px';
                $(this).css({'position': 'fixed','margin-left': left, 'top': '50px', 'left': '50%'});
                return this;
            });
        };
    })(jQuery);
    // BUY POPUP
    function buy() {
        var bg = $('div#popup-buy');
        var obj_pop = $('div#buys');
        var btnClose = obj_pop.find('span.modal_close');
        bg.animate({
            opacity: 0.2
        }, 0).fadeIn(1000);
        obj_pop.fadeIn(1000).absoluteCenter();
        btnClose.click(function () {
            bg.fadeOut();
            obj_pop.fadeOut();
        });
        bg.click(function () {
            btnClose.click();
        });
        return false;
    }
    $('a.click-buy').click(function () {
        buy();
    });
    // CERTIFICATE ADVANGATE POPUP
    function cer() {
        var bg = $('div#popup-buy');
        var obj_pop = $('div#certificate_popup');
        var btnClose = obj_pop.find('span.modal_close');
        bg.animate({
            opacity: 0.2
        }, 0).fadeIn(1000);
        obj_pop.fadeIn(1000).absoluteCenter();
        btnClose.click(function () {
            bg.fadeOut();
            obj_pop.fadeOut();
        });
        bg.click(function () {
            btnClose.click();
        });
        return false;
    }
    $('a.click_cer').click(function () {
        cer();
    });
    //back to top
    var offset = 220;
    var duration = 500;
    jQuery(window).scroll(function() {
        if (jQuery(this).scrollTop() > offset) {
            jQuery('.back-to-top').fadeIn(duration);
        } else {
            jQuery('.back-to-top').fadeOut(duration);
        }
    });
    jQuery('.back-to-top').click(function(event) {
        event.preventDefault();
        jQuery('html, body').animate({
            scrollTop: 0
        }, duration);
        return false;
    });
    //all deal choose
    var url_check = $(location).attr('href');
    $('a.list-by-category').each(function(){
        var parent = $(this).closest('span');
        var url = $(this).attr('href');
        if(url == url_check){
            var text = $(this).text();
            $(this).remove();
            parent.addClass('current');
            parent.append(text);
        }
    });
});